package com.example.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @Date 2022/3/8
 * @Created by Jonathan
 */
@Slf4j
public class ParkDemo {
    public static void main(String[] args) throws InterruptedException {
        testPark();
    }

    /**
     * isInterrupted()
     * interrupt();
     * interrupted();
     */
    public static void testPark() throws InterruptedException {
        Thread thread = new Thread(() -> {
            log.info("before park");
            LockSupport.park();
            log.info("unpark");
            LockSupport.park(); // 打断之后 park再也停不下来了
            //Thread.interrupted(); //返回打断标记之后 将打断标记改为false
            log.info("打断状态：{}", Thread.currentThread().isInterrupted());
        });
        thread.start();

        TimeUnit.SECONDS.sleep(3);
        log.info("唤醒Thread");
        thread.interrupt();
//        LockSupport.unpark(thread);
//        TimeUnit.SECONDS.sleep(1);
//        LockSupport.unpark(thread);

    }


}
